package com.fdb.efp.nls.service.impl;

import com.fdb.basic.framework.core.base.FrameworkService;
import com.fdb.efp.nls.service.dao.PrdPiccsBanceMapDao;
import com.fdb.efp.nls.service.domain.PrdPiccsBanceMap;
import com.fdb.efp.nls.service.facade.PrdPiccsBanceMapService;
import com.fdb.efp.nls.service.vo.PrdPiccsBanceMapVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>ServiceImpl: 消费贷核心产品对照表				<p>
 * @author chenqm1
 * @date 2018-05-23
 */
@Service("prdPiccsBanceMapService")
public class PrdPiccsBanceMapServiceImpl implements PrdPiccsBanceMapService, FrameworkService {
	
	private static Logger logger = LoggerFactory.getLogger(PrdPiccsBanceMapServiceImpl.class);

	@Autowired
	private PrdPiccsBanceMapDao prdPiccsBanceMapDao;
	
	/**
	 * 新增操作
	 */
	public int insertPrdPiccsBanceMap(PrdPiccsBanceMapVO inPrdPiccsBanceMapVo) {
		logger.debug("当前新增数据为:"+ inPrdPiccsBanceMapVo.toString());
		int num = 0;
		try {
			PrdPiccsBanceMap prdPiccsBanceMap = new PrdPiccsBanceMap();
			beanCopy(inPrdPiccsBanceMapVo, prdPiccsBanceMap);
			num = prdPiccsBanceMapDao.insertPrdPiccsBanceMap(prdPiccsBanceMap);
		} catch (Exception e) {
			logger.error("新增数据发生异常!", e);
			num = -1;
		}
		logger.debug("当前新增数据条数为:"+ num);
		return num;
	}

	/**
	 * 删除操作
	 */
	public int deleteByPk(PrdPiccsBanceMapVO inPrdPiccsBanceMapVo) {
		logger.debug("当前删除数据条件为:"+ inPrdPiccsBanceMapVo);
		int num = 0;
		try {
			PrdPiccsBanceMap prdPiccsBanceMap = new PrdPiccsBanceMap();
			beanCopy(inPrdPiccsBanceMapVo, prdPiccsBanceMap);
			num = prdPiccsBanceMapDao.deleteByPk(prdPiccsBanceMap);
		} catch (Exception e) {
			logger.error("删除数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPrdPiccsBanceMapVo +"删除的数据条数为"+ num);
		return num;
	}


	/**
	 * 更新操作
	 */
	public int updateByPk(PrdPiccsBanceMapVO inPrdPiccsBanceMapVo) {
		logger.debug("当前修改数据为:"+ inPrdPiccsBanceMapVo.toString());
		int num = 0;
		try {
			PrdPiccsBanceMap prdPiccsBanceMap = new PrdPiccsBanceMap();
			beanCopy(inPrdPiccsBanceMapVo, prdPiccsBanceMap);
			num = prdPiccsBanceMapDao.updateByPk(prdPiccsBanceMap);
		} catch (Exception e) {
			logger.error("修改数据发生异常!", e);
			num = -1;
		}
		logger.debug("根据条件:"+ inPrdPiccsBanceMapVo +"修改的数据条数为"+ num);
		return num;
	}
	
	/**
	 * 查询操作
	 */
	public PrdPiccsBanceMapVO queryByPk(PrdPiccsBanceMapVO inPrdPiccsBanceMapVo) {
		
		logger.debug("当前查询参数信息为:"+ inPrdPiccsBanceMapVo);
		try {
			PrdPiccsBanceMap queryPrdPiccsBanceMap = new PrdPiccsBanceMap();
			beanCopy(inPrdPiccsBanceMapVo, queryPrdPiccsBanceMap);
			PrdPiccsBanceMap queryRslPrdPiccsBanceMap = prdPiccsBanceMapDao.queryByPk(queryPrdPiccsBanceMap);
			if (Objects.nonNull(queryRslPrdPiccsBanceMap)) {
				PrdPiccsBanceMapVO outPrdPiccsBanceMapVo = beanCopy(queryRslPrdPiccsBanceMap, new PrdPiccsBanceMapVO());
				logger.debug("当前查询结果为:"+ outPrdPiccsBanceMapVo.toString());
				return outPrdPiccsBanceMapVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}


	/**
	 * 查询用户权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PrdPiccsBanceMapVO> queryAllOwner(PrdPiccsBanceMapVO prdPiccsBanceMapVo) {

		logger.debug("当前查询本人所属数据信息的参数信息为:");
		List<PrdPiccsBanceMapVO> list = null;
		try {
			List<PrdPiccsBanceMap> prdPiccsBanceMaps = prdPiccsBanceMapDao.queryAllOwnerByPage(prdPiccsBanceMapVo);
			logger.debug("当前查询本人所属数据信息的结果集数量为:"+ prdPiccsBanceMaps.size());
			pageSet(prdPiccsBanceMaps, prdPiccsBanceMapVo);
			list = (List<PrdPiccsBanceMapVO>) beansCopy(prdPiccsBanceMaps, PrdPiccsBanceMapVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PrdPiccsBanceMapVO> queryAllCurrOrg(PrdPiccsBanceMapVO prdPiccsBanceMapVo) {

		logger.debug("当前查询本人所属机构数据信息的参数信息为:");
		List<PrdPiccsBanceMap> prdPiccsBanceMaps = prdPiccsBanceMapDao.queryAllCurrOrgByPage(prdPiccsBanceMapVo);
		logger.debug("当前查询本人所属机构数据信息的结果集数量为:"+prdPiccsBanceMaps.size());
		List<PrdPiccsBanceMapVO> list = null;
		try {
			pageSet(prdPiccsBanceMaps, prdPiccsBanceMapVo);
			list = (List<PrdPiccsBanceMapVO>) beansCopy(prdPiccsBanceMaps, PrdPiccsBanceMapVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}


	/**
	 * 查询当前机构及下属机构权限数据
	 */
	@SuppressWarnings("unchecked")
	public List<PrdPiccsBanceMapVO> queryAllCurrDownOrg(PrdPiccsBanceMapVO prdPiccsBanceMapVo) {

		logger.debug("当前查询本人所属机构及以下数据信息的参数信息为:");
		List<PrdPiccsBanceMap> prdPiccsBanceMaps = prdPiccsBanceMapDao.queryAllCurrDownOrgByPage(prdPiccsBanceMapVo);
		logger.debug("当前查询本人所属机构及以下数据信息的结果集数量为:"+ prdPiccsBanceMaps.size());
		List<PrdPiccsBanceMapVO> list = null;
		try {
			pageSet(prdPiccsBanceMaps, prdPiccsBanceMapVo);
			list = (List<PrdPiccsBanceMapVO>) beansCopy(prdPiccsBanceMaps, PrdPiccsBanceMapVO.class);
		} catch (Exception e) {
			logger.error("数据转换出现异常!", e);
		}
		
		return list;
	
	}

	@Override
	public PrdPiccsBanceMapVO queryByCondition(PrdPiccsBanceMapVO prdPiccsBanceMapVo) {
		logger.debug("当前查询参数信息为:"+ prdPiccsBanceMapVo);
		try {
			PrdPiccsBanceMap prdPiccsBanceMap = new PrdPiccsBanceMap();
			beanCopy(prdPiccsBanceMapVo, prdPiccsBanceMap);
			PrdPiccsBanceMap queryRslPrdPiccsBanceMap = prdPiccsBanceMapDao.queryByCondition(prdPiccsBanceMap);
			if (Objects.nonNull(queryRslPrdPiccsBanceMap)) {
				PrdPiccsBanceMapVO outPrdPiccsBanceMapVo = beanCopy(queryRslPrdPiccsBanceMap, new PrdPiccsBanceMapVO());
				logger.debug("当前查询结果为:"+ outPrdPiccsBanceMapVo.toString());
				return outPrdPiccsBanceMapVo;
			} else {
				logger.debug("当前查询结果为空!");
			}
		} catch (Exception e) {
			logger.error("查询数据发生异常!", e);
		}
		return null;
	}
}
